<template>
  <div>
<!--    <el-form   :model="pageForm" label-width="80px" :rules="pageFormRules" ref="pageForm" >-->
    <el-form   :model="pageForm" label-width="80px" ref="pageForm" >
   <!--   <el-form-item label="阶段" prop="siteId">
        <el-select v-model="pageForm.dictDataId" placeholder="请选择阶段">
          <el-option
            v-for="item in dictDateList"
            :key="item.dictDataId"
            :label="item.dictLabel"
            :value="item.dictDataId">
          </el-option>
        </el-select>
      </el-form-item>-->

      <el-form-item label="题目名称" prop="pageName">
        <el-input v-model="pageForm.quesName" auto-complete="off" ></el-input>
      </el-form-item>

      <el-form-item label="题目描述" prop="pageAliase">
        <el-input v-model="pageForm.quesDescript" auto-complete="off" ></el-input>
      </el-form-item>
      <el-form-item label="题目阶段" prop="pageWebPath">
        <el-input v-model="pageForm.complexity" auto-complete="off" ></el-input>
      </el-form-item>
      <el-form-item label="难易程度" prop="pageWebPath">
        <el-input v-model="pageForm.complexity" auto-complete="off" ></el-input>
      </el-form-item>
      <el-form-item label="题目状态">
        <el-radio-group v-model="pageForm.status">
          <el-radio class="radio" label="0">启用</el-radio>
          <el-radio class="radio" label="1">停用</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="关键字" prop="pageWebPath">
        <el-input v-model="pageForm.complexity" auto-complete="off" ></el-input>
      </el-form-item>
      <el-form-item label="备注" prop="pageWebPath">
        <el-input v-model="pageForm.complexity" auto-complete="off" ></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="go_back">返回</el-button>
      <el-button type="primary" @click.native="addSubmit" :loading="addLoading">提交</el-button>
    </div>
  </div>
</template>
<script>
  import * as cmsApi from '../api/cms'
  export default{
    data(){
      return {
        //模版列表
        templateList:[],
        addLoading: false,//加载效果标记
        //新增界面数据
        pageForm: {
          siteId:'',
          templateId:'',
          pageName: '',
          pageAliase: '',
          pageWebPath: '',
          dataUrl:'',
          pageParameter:'',
          pagePhysicalPath:'',
          pageType:'',
          pageCreateTime: new Date()
        },
        pageFormRules: {
          siteId:[
            {required: true, message: '请选择站点', trigger: 'blur'}
          ],
          templateId:[
            {required: true, message: '请选择模版', trigger: 'blur'}
          ],
          pageName: [
            {required: true, message: '请输入页面名称', trigger: 'blur'}
          ],
          pageWebPath: [
            {required: true, message: '请输入访问路径', trigger: 'blur'}
          ],
          pagePhysicalPath: [
            {required: true, message: '请输入物理路径', trigger: 'blur'}
          ]
        },
        siteList:[],
        goback_params: {
          page: this.$route.query.page,
          siteId:this.$route.query.siteId,
        }
      }
    },
    methods:{
      go_back(){
        this.$router.push({
          path: '/cms/page/list', query: {
            page: this.$route.query.page,
            siteId:this.$route.query.siteId
          }
        })
      },
      addSubmit(){
        this.$refs.pageForm.validate((valid) => {
          if (valid) {
            this.$confirm('确认提交吗？', '提示', {}).then(() => {
              this.addLoading = true;
              cmsApi.page_add(this.pageForm).then((res) => {
                  console.log(res);
                if(res.success){
                  this.addLoading = false;
                  //NProgress.done();
                  this.$message({
                    message: '提交成功',
                    type: 'success'
                  });
                  this.$refs['pageForm'].resetFields();

                }else if(res.message){
                  this.addLoading = false;
                  this.$message.error(res.message);
                }else{
                  this.addLoading = false;
                  this.$message.error('提交失败');
                }
              });
            });
          }
        });
      }
    },
    created: function () {

    },
    mounted:function(){

      //初始化站点列表
      this.dictDateList = [
        {
          dictDataId:'1',
          dictDataLabel:'一阶段'
        },
        {
          dictDataId:'2',
          dictDataLabel:'二阶段'
        }
      ]

    }
  }
</script>
<style>

</style>
